package com.tour.service.impl;

import com.tour.bean.ReturnT;
import com.tour.bean.Ticketinfo;
import com.tour.dao.TicketinfoMapper;
import com.tour.service.TicketinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName TicketinfoServiceImpl
 * @Author 张梦兴
 * @Date 2020/3/17 16:24
 * @describe
 */
@Service
public class TicketinfoServiceImpl implements TicketinfoService {

    @Autowired
    private TicketinfoMapper ticketinfoMapper;


    @Override
    public ReturnT<String> insert(Ticketinfo ticketinfo) {

        // valid
        if (ticketinfo == null) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, "必要参数缺失");
        }

        ticketinfoMapper.insert(ticketinfo);
        return ReturnT.SUCCESS;
    }


    @Override
    public ReturnT<String> delete(int id) {
        int ret = ticketinfoMapper.delete(id);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public ReturnT<String> update(Ticketinfo ticketinfo) {
        int ret = ticketinfoMapper.update(ticketinfo);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public Ticketinfo load(int id) {
        return ticketinfoMapper.load(id);
    }


    @Override
    public Map<String,Object> pageList(int offset, int pagesize, String sStation, String lStation, String sdate) {

        Map<String,Object> param=new HashMap<>();
        param.put("offset",offset);
        param.put("pageSize",pagesize);
        param.put("sStation",sStation);
        param.put("lStation",lStation);
        param.put("sdate", sdate);

        List<Ticketinfo> pageList = ticketinfoMapper.pageList(param);
        int totalCount = ticketinfoMapper.pageListCount(param);

        // result
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);

        return result;
    }

}

